/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：PreAttackStatus.java <br>
 * 创建时间：2014-1-6 上午11:41:22 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.battle.proc;

import com.orhanobut.logger.Logger;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.battle.BattleScreen;
import lostland.gmud.exv2.battle.ViewScreen;
import lostland.gmud.exv2.data.Gesture;
import lostland.gmud.exv2.data.Item;
import lostland.gmud.exv2.data.Npc;

/**
 * 类名：PreAttackStatus <br>
 * 说明：预攻击状态
 *
 * @author 12548
 */
public class PreAttackStatus extends Status {

	String prefix = "";

	Gesture ges;
	boolean inDouble = false;
	boolean inHubo = false;

	boolean isAnti = false;

	boolean nodb = false;

	int round = 0;
	int db = 2;

	int hbround = 0;

	public float hitBouns = 0f;
	public float dmgBouns = 0f;

	public Item anqi = null;


	public PreAttackStatus(Npc zdp, Npc bdp, Gesture ges) {
		super(zdp, bdp);
		this.ges = ges;
		prefix = "";
		inDouble = false;
		inHubo = false;
		round = 0;
		hbround = 0;
	}

	public PreAttackStatus(Npc zdp, Npc bdp, Gesture ges, String prefix) {
		super(zdp, bdp);
		this.ges = ges;
		this.prefix = prefix;
		inDouble = false;
		inHubo = false;
		round = 0;
		hbround = 0;
	}

	public PreAttackStatus(Npc zdp, Npc bdp, Gesture ges, String prefix, boolean inDouble) {
		super(zdp, bdp);
		this.ges = ges;
		this.prefix = prefix;
		this.inDouble = inDouble;
		inHubo = false;
		round = 0;
		hbround = 0;
	}

	public PreAttackStatus(Npc zdp, Npc bdp, Gesture ges, String prefix, boolean inDouble, boolean inHubo) {
		super(zdp, bdp);
		this.ges = ges;
		this.prefix = prefix;
		this.inDouble = inDouble;
		this.inHubo = inHubo;
		round = 0;
		hbround = 0;
	}

	public PreAttackStatus(Npc zdp, Npc bdp, Gesture ges, String prefix, boolean inDouble, boolean inHubo, boolean isAnti) {
		super(zdp, bdp);
		this.ges = ges;
		this.prefix = prefix;
		this.inDouble = inDouble;
		this.inHubo = inHubo;
		this.isAnti = isAnti;
		round = 0;
		hbround = 0;
	}


	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.battle.proc.Status#execute()
	 */
	@Override
	public void execute() {

		if ((ges != null) || (anqi != null)) {
			nodb = true;
		}

		if (zdp.haveTalent(1001)) {
			db = 3;
		}

		if (inDouble || (anqi != null)) {
			process();
		} else {
			if (inHubo) {
				bdp.setTemp_dmg_multiplier(bdp.getTemp_dmg_multiplier() * (0.6 + zdp.skills[42] * 0.001));
				if (doubleAttack() || round > 0) {
					if (round < (db - 1)) {
						pushToBattle();
						PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【连击" + (round + 1) + "/" + db + "】", true);
						pas.dmgBouns = dmgBouns;
						pas.hitBouns = hitBouns;
						pas.pushToBattle();
						round++;
					} else {
						PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【连击" + (round + 1) + "/" + db + "】", true);
						pas.dmgBouns = dmgBouns;
						pas.hitBouns = hitBouns;
						pas.pushToBattle();
					}
				} else {
					process();
				}
			} else if (zdp.skillsckd[4] != 42) {
				if (doubleAttack() || round > 0) {
					if (round < (db - 1)) {
						pushToBattle();
						PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【连击" + (round + 1) + "/" + db + "】", true);
						pas.dmgBouns = dmgBouns;
						pas.hitBouns = hitBouns;
						pas.pushToBattle();
						round++;
					} else {
						PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【连击" + (round + 1) + "/" + db + "】", true);
						pas.dmgBouns = dmgBouns;
						pas.hitBouns = hitBouns;
						pas.pushToBattle();
					}
				} else {
					process();
				}
			} else {
				if (hbround < 1) {
					pushToBattle();
					PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【左右互搏" + (hbround + 1) + "/" + 2 + "】", false, true);
					pas.dmgBouns = dmgBouns;
					pas.hitBouns = hitBouns;
					pas.pushToBattle();
					hbround++;
				} else {
					PreAttackStatus pas = new PreAttackStatus(zdp, bdp, ges, prefix + "【左右互搏" + (hbround + 1) + "/" + 2 + "】", false, true);
					pas.dmgBouns = dmgBouns;
					pas.hitBouns = hitBouns;
					pas.pushToBattle();
				}
			}
		}
	}

	void process() {
		final AttackStatus as = new AttackStatus(zdp, bdp, isAnti);

		if (anqi == null) {
			as.as = zdp.getAttackSkill();
		} else {
			int sklid = anqi.getSubkind();
			if (Gmud.skill[sklid].pos != 5) {
				sklid = Gmud.mc.getEquipedSkill(5).id;
			}
			as.as = Gmud.skill[sklid];
		}

		if (ges == null) {
			as.ag = zdp.cg();
		} else {
			as.ag = ges;
		}


		if (!isAnti && (anqi == null)) {
			if (bdp.skillsckd[4] == 44) {
				zdp.setTemp_dmg_multiplier(zdp.getTemp_dmg_multiplier() * (0.6 + bdp.skills[44] * 0.001));
				new PreAttackStatus(bdp, zdp, as.ag, "【斗转星移】", inDouble, inHubo, true).pushToBattle();
			}
		}


		new ViewScreen(prefix + BattleScreen.bsp(zdp, bdp, as.ag.c, anqi)).pushToGame();


		as.dmgBouns = dmgBouns;
		as.hitBouns = hitBouns;
		as.anqi = anqi;
		as.pushToBattle();
	}

	boolean doubleAttack() {
		if (anqi != null) return false;

		if (nodb || bdp.haveTalent(30))
			return false;

		if (zdp.haveTalent(1008)) // 天赋效果1008
			return true;

		double rr = 0.05 * Game.getInstance().data.game_difficulty + 0.05;

//		if(zdp.using(GmudGame.getInstance().xdata.get("SKILLID_踏雪无痕")))
//		{
//			rr *= 1.1;
//			GmudGame.logInfo("PreAttackStatus", "踏雪无痕：连击率增加");
//		}
//
//		if(bdp.using(GmudGame.getInstance().xdata.get("SKILLID_飞蝶身法")))
//		{
//			rr *= 0.8;
//			GmudGame.logInfo("PreAttackStatus", "飞蝶身法：连击率减少");
//		}


		boolean da = Math.random() < rr;
		Logger.i("连击：" + da);
		return da;
	}

}
